<template>
<div class="add-agent">
  <dept-dailog
    :title="$t('config.agent.addDept')"
    :isShow="isAdd"
    :form="addForm"
    @close="closeDailog"
  ></dept-dailog>
</div>
</template>
<script>
  import { deepClone } from '@/utils/m7Utils'
  import DeptDailog from './DeptDailog'
  export default {
    name: 'AddDept',
    data () {
      return {
        submitForm: null
      }
    },
    props: {
      isAdd: Boolean,
      addForm: {
        type: Object,
        default: function () {
          return {}
        }
      }
    },
    components: {
      DeptDailog
    },
    methods: {
      closeDailog (data) {
        if (data.type === 'submit') {
          this.submitForm = deepClone(data.addForm)
          delete this.submitForm.prentsName
          this.$store.dispatch('addDept', this.submitForm).then((res) => {
            if (res && res.success) {
              // this.$store.dispatch('addCache', { type: 'depts', data: res.dept })
              this.$message.success(this.$t('agentSetting.agentSetting67'))
              this.$emit('close', data)
            }
          })
        } else {
          this.$emit('close', data)
        }
      }
    }
  }
</script>
